# conftest.py
import pytest


@pytest.fixture()
def db():
    print('\nDB Opened !!!')
    yield
    print('\nDB Closed !!!')


# 绘画作用域范围，session：每个session只运行一次
@pytest.fixture(scope='session', autouse=True)
def session_scope():
    print('\nSession Opened')
    yield
    print('Session Closed')


# 类作用域范围，class：每个class的所有test只运行一次
@pytest.fixture(scope='class')
def class_scope():
    print('\nClass Opened')
    yield
    print('Class Closed')


# 模块作用范围，module：每个module的所有test只运行一次
@pytest.fixture(scope='module', autouse=True)
def module_scope():
    print('\nModule Opened')
    yield
    print('Module Closed')


#  方法固件作用域范围 function：每个test都运行，默认是function的scope
@pytest.fixture(scope='function', autouse=True)
def function_scope():
    print('\nFunction opened')
    yield
    print('Function closed')
